﻿using System;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;

namespace IFD2
{
    public partial class QueryFareStairs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["ACL"].ToString().IndexOf("SB2") < 0)
                {
                    Response.Redirect("unauthorized.aspx");
                }
                if (Request.QueryString["fare_code"] == null)
                {
                    lblError.Text = "Illegal page call!";
                }
                else
                {
                    lblAirline.Text = Request.QueryString["airline"];
                    lblFareCode.Text = Request.QueryString["fare_code"];
                    lblSegNo.Text = Request.QueryString["seg_sn"];

                    RefreshStairs();
                }
            }
        }

        protected void lbtnQuery_Click(object sender, EventArgs e)
        {
            RefreshStairs();
        }

        protected void RefreshStairs()
        {
            //旅客是否会由于产品时间优惠而改变乘机日期？价格变化对旅客更透明是否有优势？

            TableRow tabRow;
            TableCell tabCell;

            SqlCommand cmd = new SqlCommand();
            SqlParameter para;
            DataTable dtStairs = new DataTable();
            cmd.CommandText = "bll_query_get_fare_approved_stairs";
            para = cmd.Parameters.AddWithValue("@airline", lblAirline.Text);
            para = cmd.Parameters.AddWithValue("@fare_code", lblFareCode.Text);
            para = cmd.Parameters.AddWithValue("@seg_sn", lblSegNo.Text);
            para = cmd.Parameters.AddWithValue("@user_airline", Session["AIRLINE"].ToString());
            para = cmd.Parameters.AddWithValue("@office", Session["OFFICE"].ToString());
            para = cmd.Parameters.AddWithValue("@user", Session["USER"].ToString());
            TinyDAL.Exec(ref cmd, ref dtStairs);
            int height;
            
            tabRow = new TableRow();
            foreach (DataRow rowAdtPrice in dtStairs.Rows)
            {
                height = Convert.ToInt16(rowAdtPrice["adt_price"]) / 20;
                if (height < 10)
                    height = 10;
                tabCell = new TableCell();
                tabCell.Text = Convert.ToSingle(rowAdtPrice["adt_price"]).ToString("F2")+"<br/><img src='images/bar_green.bmp' width='10' height='" + height.ToString() + "'><br/>" + Convert.ToInt16(rowAdtPrice["fltdate_diff"]).ToString("+#;-#;0");
                tabCell.VerticalAlign = VerticalAlign.Bottom;
                tabCell.HorizontalAlign = HorizontalAlign.Center;
                tabCell.Width = 70;
                tabRow.Cells.Add(tabCell);
            }
            tabAdtPrice.Rows.Add(tabRow);

            tabRow = new TableRow();
            foreach (DataRow rowChdPrice in dtStairs.Rows)
            {
                height = Convert.ToInt16(rowChdPrice["chd_price"]) / 20;
                if (height < 10)
                    height = 10;
                tabCell = new TableCell();
                tabCell.Text = Convert.ToSingle(rowChdPrice["chd_price"]).ToString("F2")+"<br/><img src='images/bar_green.bmp' width='10' height='" + height.ToString() + "'><br/>" + Convert.ToInt16(rowChdPrice["fltdate_diff"]).ToString("+#;-#;0");
                tabCell.VerticalAlign = VerticalAlign.Bottom;
                tabCell.HorizontalAlign = HorizontalAlign.Center;
                tabCell.Width = 70;
                tabRow.Cells.Add(tabCell);
            }
            tabChdPrice.Rows.Add(tabRow);

            tabRow = new TableRow();
            foreach (DataRow rowInfPrice in dtStairs.Rows)
            {
                height = Convert.ToInt16(rowInfPrice["inf_price"]) / 20;
                if (height < 10)
                    height = 10;
                tabCell = new TableCell();
                tabCell.Text = Convert.ToSingle(rowInfPrice["inf_price"]).ToString("F2") + "<br/><img src='images/bar_green.bmp' width='10' height='" + height.ToString() + "'><br/>" + Convert.ToInt16(rowInfPrice["fltdate_diff"]).ToString("+#;-#;0");
                tabCell.VerticalAlign = VerticalAlign.Bottom;
                tabCell.HorizontalAlign = HorizontalAlign.Center;
                tabCell.Width = 70;
                tabRow.Cells.Add(tabCell);
            }
            tabInfPrice.Rows.Add(tabRow);
        }
    }
}